using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;

namespace Elementum
{
   public class StageMenu : MainMenu
    {
        MenuItem _restart;

        public StageMenu(Stage stage):base(stage)
        {
        }

        protected override void InitializeItem(Stage stage, string menuPath)
        {
            _newGame = new MenuItem(stage, new Animation(menuPath, new Rectangle(2, 2, 264, 66), new Point(264, 66)));
            _newGame.Position = new Vector2(50 + 264 / 2, 80);
            _restart = new MenuItem(stage, new Animation(menuPath, new Rectangle(2, 70, 198, 66), new Point(198, 66)));
            _restart.Position = new Vector2(50  + 198 / 2, 160);
            _quit = new MenuItem(stage, new Animation(menuPath, new Rectangle(2, 138, 106, 66), new Point(106, 66)));
            _quit.Position = new Vector2(50 + 106 / 2, 240);

            _children.Add(_restart);
            _children.Add(_newGame);
            _children.Add(_quit);

            _newGame.TouchStateAction += MenuAction;
            _quit.TouchStateAction += MenuAction;
            _restart.TouchStateAction += MenuAction;
        }

        public override void MenuAction(VisibleObject pressedObject, TouchLocationState state)
        {
            if (state == TouchLocationState.Pressed)
            {
                Transition tra;

                //Animation ani = new Animation("images/system/black", new Point(820, 500));
                //tra = new AlphaTransition(ani, 1, 0, 10, 80);
                //tra.Register(_stage);

                tra = new DefauldTransition(0, 1, 5, 70);
                tra.Register(_stage);
                tra = new DefauldTransition(1, 1, 65, 85);
                tra.Register(_stage);

                tra = new DefauldTransition(0, 1, 10, 80);
                if (pressedObject == _newGame)
                    tra.TransitionDoneAction += NewGame;
                if (pressedObject == _restart)
                    tra.TransitionDoneAction += Restart;
                if (pressedObject == _quit)
                    tra.TransitionDoneAction += Quit;
                tra.Register(_stage);
                PressMotion(pressedObject);
            }
        }

        private void Restart() {
            _stage.Restart();
            StageManager.ReLoadStage();
        }

    }
}
